
%!TEX program = xelatex
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[10pt]{article} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 一些常用的包总结在另一个文件里
\input{wang_preamble.tex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 选择Windows操作系统写中文文档，使用 xelatex 或 lualatex 编译器
%\usepackage{xeCJK} % 处理中文、日文和韩文（统称为 CJK 文字）的排版
%\setCJKmainfont{SimSun} % 设置正文字体为宋体
%\setCJKmonofont{SimHei} % 设置加粗字体为黑体
%\setCJKsansfont{SimHei} % 黑体

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%选择Mac操作系统写中文文档，使用 xelatex 或 lualatex 编译器
\usepackage{xeCJK} % 支持中文字体
\setCJKmainfont{Songti SC} % 设置主要中文字体，用于正文中的中文文本。设置主要中文字体为宋体
%\setCJKmonofont{Menlo} % 设置等宽中文字体，用于代码块、等宽文本等。设置等宽中文字体为 Menlo
%\setCJKsansfont{PingFang SC} % 设置无衬线中文字体，用于标题、图表标签等。设置无衬线中文字体为 PingFang SC
%\setCJKromanfont{Songti SC} % 设置罗马中文字体，用于罗马字体中的中文文本。设置罗马中文字体为宋体

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%选择输出文档的三种类型：
%\newcommand{\showsolution}{0} %%设置showsolution=0, 编译生成试卷
\newcommand{\showsolution}{1} %%设置showsolution=1, 编译生成试卷解答

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 填写课程信息：
\newcommand{\CourseName}{高等代数测验3 - 矩阵}
\newcommand{\CourseStudents}{王立庆（2024 级数学与应用数学1班）}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%考完发给学生：

\usepackage{titling}
\setlength{\droptitle}{-2cm}   % 标题上移2cm


\ifnum\showsolution=0
\title{\CourseName }
\author{学号 \underline{\hspace{4cm}} \hspace{1cm} 姓名 \underline{\hspace{4cm}} }
\fi

\ifnum\showsolution=1
\title{\CourseName \,\, 解答 }
\author{\CourseStudents}
\fi

\renewcommand{\today}{\number\year \,年 \number\month \,月 \number\day \,日}
\date{2024年12月5日}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 考完发给学生：给文档加标题、作者、日期、摘要

\maketitle

\thispagestyle{fancy} % 第一页也显示“第几页，共几页”的信息。


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage 
\item %第1题
设 $A=\begin{pmatrix} 2&1 \\ 2&4 \\ \end{pmatrix}$, 设 $f(x)=x^2-2x+3$, 求 $f(A)$. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{5cm}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第1题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  将矩阵 $A$ 代入未知数 $x$ 的位置，并将常数项乘以单位矩阵，可得
\begin{equation*}
\begin{aligned}
f(A)=A^2-2A+3E 
& = \begin{pmatrix} 2&1 \\ 2&4 \\ \end{pmatrix}\begin{pmatrix} 2&1 \\ 2&4 \\ \end{pmatrix}
- 2 \begin{pmatrix} 2&1 \\ 2&4 \\ \end{pmatrix}
+ 3 \begin{pmatrix} 1&0 \\ 0&1 \\ \end{pmatrix} \\ 
& = \begin{pmatrix} 6&6 \\ 12&18 \\ \end{pmatrix}
- \begin{pmatrix} 4&2 \\ 4&8 \\ \end{pmatrix}
+ \begin{pmatrix} 3&0 \\ 0&3 \\ \end{pmatrix} \\ 
& = \begin{pmatrix} 5&4 \\ 8&13 \\ \end{pmatrix}. 
\end{aligned}
\end{equation*}

\item  使用R语言计算矩阵 $A$ 的多项式：
\begin{lstlisting}[language=R]
library(pracma)
A=matrix(c(2,1,2,4),nrow=2,byrow=T) #按行输入矩阵
print(A)
E=diag(2) #单位矩阵
B=A%*%A-2*A+3*E
print(B)
\end{lstlisting}

\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage 
\item %第2题
设 $A=\begin{pmatrix} 1&2 \\ 0&1 \\ \end{pmatrix}$, 求所有的矩阵 $B$ 使得 $AB=BA$. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{5cm}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第2题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  设矩阵 $B=\begin{pmatrix} x&y \\ u&v \\ \end{pmatrix}$ 从 $AB=BA$ 可得
$$
\begin{pmatrix} 1&2 \\ 0&1 \\ \end{pmatrix}
\begin{pmatrix} x&y \\ u&v \\ \end{pmatrix}
=
\begin{pmatrix} x&y \\ u&v \\ \end{pmatrix}
\begin{pmatrix} 1&2 \\ 0&1 \\ \end{pmatrix}. 
$$

\item  计算矩阵的乘法，可得
$$
\begin{pmatrix} x+2u & y+2v \\ u&v \\ \end{pmatrix}
=
\begin{pmatrix} x&2x+y \\ u&2u+v \\ \end{pmatrix}. 
$$

\item  根据矩阵的分量对应相等，可得 $u=0, x=v$. 因此所求矩阵 $B$ 的一般形式为
$$
B=\begin{pmatrix} x&y \\ 0&x \\ \end{pmatrix}, 
$$
其中 $x,y$ 为任意实数。


\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage 
\item %第3题
计算矩阵 $A=\begin{pmatrix}  1&2&1 \\ 3&1&4 \\ 1&5&1 \\ \end{pmatrix}$ 的伴随矩阵。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{5cm}
\newpage 
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第3题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  计算代数余子式，可得 
\begin{equation*}
\begin{aligned}
& A_{11} = -19, \hspace{0.5cm} 
A_{12} = 1, \hspace{0.5cm} 
A_{13} = 14, \\ 
& A_{21} = 3, \hspace{0.5cm} 
A_{22} = 0, \hspace{0.5cm} 
A_{23} = -3, \\ 
& A_{31} = 7, \hspace{0.5cm} 
A_{32} = -1, \hspace{0.5cm} 
A_{33} = -5. 
\end{aligned}
\end{equation*}

\item  根据伴随矩阵的定义，可得
$$
A^* = \begin{pmatrix}  -19&3&7 \\ 1&0&-1 \\ 14&-3&-5 \\  \end{pmatrix}. 
$$

\item  使用R语言计算矩阵 $A$ 的每个代数余子式：
\begin{lstlisting}[language=R]
library(pracma)
A=matrix(c(1,2,1,3,1,4,1,5,1),nrow=3,byrow=T)
B=matrix(0,nrow=3,ncol=3)
for (i in 1:3){
  for (j in 1:3){
  B[i,j]=(-1)^(i+j)*det(A[-i,-j]) #计算代数余子式
  mystring=sprintf('A%d%d = %3.0f',i,j,B[i,j])
  print(mystring)
  }
}
round(A%*%t(B),1) # 验证
\end{lstlisting}

\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage 
\item %第4题
使用初等变换计算矩阵
$
A=\begin{pmatrix} 
1&2&0 \\ 
3&0&1 \\ 
5&11&0 \\
\end{pmatrix}
$
的逆阵。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{5cm}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第4题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  将矩阵 $(A, E)$ 进行初等行变换，化为行最简形，可得
$$
\begin{pmatrix} 1&2&0 &1&0&0  \\ 3&0&1 &0&1&0 \\ 5&11&0 &0&0&1 \\ \end{pmatrix}
\xrightarrow{\mathrm{RREF} }
\begin{pmatrix} 1&0&0 &11&0&-2  \\ 0&1&0 &-5&0&1 \\ 0&0&1 &-33&1&6 \\ \end{pmatrix}. 
$$

\item  可得矩阵 $A$ 的逆阵为
$$
A^{-1} = \begin{pmatrix} 11&0&-2  \\ -5&0&1 \\ -33&1&6 \\ \end{pmatrix}. 
$$

\item  使用R语言计算矩阵 $(A,E)$ 的行最简形：
\begin{lstlisting}[language=R]
A=matrix(c(1,2,0,3,0,1,5,11,0),nrow=3,byrow=T)
E=diag(3) #单位矩阵
AE=cbind(A,E) #左右连接两个矩阵
print(AE)
print(rref(AE)) #计算行最简形
\end{lstlisting}

\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage 
\item %第5题
求解矩阵方程 
$
\begin{pmatrix} 
3&1 \\ 
2&1 \\ 
\end{pmatrix} 
X =
\begin{pmatrix} 
2&5 \\ 
5&2 \\ 
\end{pmatrix}. 
$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{5cm}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第5题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  记矩阵方程为 $AX=B$. 将矩阵 $(A, B)$ 进行初等行变换，化为行最简形，可得
$$
\begin{pmatrix} 2&1 &2&5  \\ 3&1 &5&2 \\  \end{pmatrix}
\xrightarrow{\mathrm{RREF} }
\begin{pmatrix} 1&0 &-3&3  \\ 0&1& 11&-4 \\  \end{pmatrix}. 
$$

\item  可得所求矩阵 $X=A^{-1}B$ 为
$$
X = \begin{pmatrix} -3&3  \\ 11&-4 \\ \end{pmatrix}. 
$$

\item  使用R语言计算矩阵 $(A,B)$ 的行最简形：
\begin{lstlisting}[language=R]
A=matrix(c(3,1,2,1),nrow=2,byrow=T)
B=matrix(c(2,5,5,2),nrow=2,byrow=T)
AB=cbind(A,B) #左右连接两个矩阵
print(AB)
print(rref(AB)) #计算行最简形
\end{lstlisting}

\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage 
\item %第6题
%\begin{enumerate}
%\item  
使用初等变换将矩阵
$
A=\begin{pmatrix} 
1&2&1&2 \\ 
1&3&1&3 \\ 
0&2&0&2 \\ 
\end{pmatrix}
$
化为形如 $B=\begin{pmatrix} E_r & O \\ O & O \end{pmatrix}$ 的标准形。
%\item  将上述结果写成 $P_s\cdots P_2P_1AQ_1Q_2\cdots Q_t=B$ 的形式，其中 $P_1,P_2,\cdots,P_s$ 和 $Q_1,Q_2,\cdots,Q_t$ 都是初等矩阵。
%\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 试卷留空位
\ifnum\showsolution=0
\vspace{5cm}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%第6题解答
\ifnum\showsolution=1

{\color{red}解答：
\begin{enumerate}[label={\arabic*.}]
\item  先通过初等行变换将矩阵 $A$ 化为行最简形，
$$
\begin{pmatrix} 1&2&1&2 \\ 1&3&1&3 \\ 0&2&0&2 \\  \end{pmatrix}
\xrightarrow{\mathrm{RREF} }
\begin{pmatrix} 1&0 &1&0  \\ 0&1& 0&1 \\  0&0&0&0 \\  \end{pmatrix}. 
$$

\item  再通过初等列变换将上述得到的矩阵化为相抵标准形，
$$
\begin{pmatrix} 1&0 &1&0  \\ 0&1& 0&1 \\  0&0&0&0 \\  \end{pmatrix}
\xrightarrow{\mathrm{ECO} }
\begin{pmatrix} 1&0 &0&0  \\ 0&1& 0&0 \\  0&0&0&0 \\  \end{pmatrix}. 
$$

\item  因为使用了三次初等行变换、两次初等列变换，所以可得
$$
P_3P_2P_1 A Q_1Q_2 = B,
$$
其中 $P_1,P_2,P_3$ 是三阶的初等矩阵，$Q_1,Q_2$ 是四阶的初等矩阵。

\end{enumerate}
}

\vspace{0.2cm}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%试卷结束
\end{document}


